export const mixin = {
	methods: {
		//关于课程等级
		courseType(courseLevel) {
			let value = '';
			switch (courseLevel) {
				case 1:
					value = '初级'
					break;
				case 2:
					value = '中级'
					break;
				case 3:
					value = '高级'
					break;
			}
			return value;
		},
		//关于课程观看人数
		courseNumber(value) {
			const newValue = ['', '', '']
			let fr = 1000
			let num = 3
			let text1 = ''
			let fm = 1
			while (value / fr >= 1) {
				fr *= 10
				num += 1
				// console.log('数字', value / fr, 'num:', num)
			}
			if (num <= 8) { // 万
				text1 = parseInt(num - 4) / 3 > 1 ? '千万' : 'W'
				// tslint:disable-next-line:no-shadowed-variable
				fm = text1 === 'W' ? 10000 : 10000000
				if (value % fm === 0) {
					newValue[0] = parseInt(value / fm) + ''
				} else {
					newValue[0] = parseFloat(value / fm).toFixed(1) + ''
				}
				newValue[1] = text1
			}
			if (value < 1000) {
				newValue[0] = value + ''
				newValue[1] = ''
			}
			return newValue.join('')
		},
		getHeight(HeaderSearch, HomeTbas) {
			let searchHeight = 0;
			let tabsHeight = 0;
			let height = 0;
			//header-search高度
			if (HeaderSearch) {
				let searchView = uni.createSelectorQuery().select(HeaderSearch);
				searchView.boundingClientRect(data => {
					searchHeight = data.height;
				}).exec();
			}
			//home-tabs高度
			if (HomeTbas) {
				let tabsView = uni.createSelectorQuery().select(HomeTbas);
				tabsView.boundingClientRect(data => {
					tabsHeight = data.height;
				}).exec();
			}

			uni.getSystemInfo({
				success(res) {
					height = res.windowHeight - searchHeight - tabsHeight;
				}
			})
			return height;
		}
	}
}